/*
 * File Name:               MatrixUtil.cs
 *
 * Description:             普通类
 * Author:                  chengyongxin
 * Create Date:             2016/12/12
 */

using UnityEngine;

//public class MatrixUtil
//{
//    //public static XVector3 ExtractTranslationFromMatrix(ref Matrix4x4 matrix)
//    //{
//    //    XVector3 translate;
//    //    translate.x = matrix.m03;
//    //    translate.y = matrix.m13;
//    //    translate.z = matrix.m23;
//    //    return translate;
//    //}

//    ///// <summary>
//    ///// Extract rotation XQuaternion from transform matrix.
//    ///// </summary>
//    ///// <param name="matrix">Transform matrix. This parameter is passed by reference
//    ///// to improve performance; no changes will be made to it.</param>
//    ///// <returns>
//    ///// XQuaternion representation of rotation transform.
//    ///// </returns>
//    //public static XQuaternion ExtractRotationFromMatrix(ref Matrix4x4 matrix)
//    //{
//    //    XVector3 forward;
//    //    forward.x = matrix.m02;
//    //    forward.y = matrix.m12;
//    //    forward.z = matrix.m22;

//    //    XVector3 upwards;
//    //    upwards.x = matrix.m01;
//    //    upwards.y = matrix.m11;
//    //    upwards.z = matrix.m21;

//    //    return XQuaternion.LookRotation(forward, upwards);
//    //}

//    ///// <summary>
//    ///// Extract scale from transform matrix.
//    ///// </summary>
//    ///// <param name="matrix">Transform matrix. This parameter is passed by reference
//    ///// to improve performance; no changes will be made to it.</param>
//    ///// <returns>
//    ///// Scale vector.
//    ///// </returns>
//    //public static XVector3 ExtractScaleFromMatrix(ref Matrix4x4 matrix)
//    //{
//    //    XVector3 scale;
//    //    scale.x = new Vector4(matrix.m00, matrix.m10, matrix.m20, matrix.m30).magnitude;
//    //    scale.y = new Vector4(matrix.m01, matrix.m11, matrix.m21, matrix.m31).magnitude;
//    //    scale.z = new Vector4(matrix.m02, matrix.m12, matrix.m22, matrix.m32).magnitude;
//    //    return scale;
//    //}

//    ///// <summary>
//    ///// Extract position, rotation and scale from TRS matrix.
//    ///// </summary>
//    ///// <param name="matrix">Transform matrix. This parameter is passed by reference
//    ///// to improve performance; no changes will be made to it.</param>
//    ///// <param name="localPosition">Output position.</param>
//    ///// <param name="localRotation">Output rotation.</param>
//    ///// <param name="localScale">Output scale.</param>
//    //public static void DecomposeMatrix(ref Matrix4x4 matrix, out XVector3 localPosition, out XQuaternion localRotation, out XVector3 localScale)
//    //{
//    //    localPosition = ExtractTranslationFromMatrix(ref matrix);
//    //    localRotation = ExtractRotationFromMatrix(ref matrix);
//    //    localScale = ExtractScaleFromMatrix(ref matrix);
//    //}

//    ///// <summary>
//    ///// Set transform component from TRS matrix.
//    ///// </summary>
//    ///// <param name="transform">Transform component.</param>
//    ///// <param name="matrix">Transform matrix. This parameter is passed by reference
//    ///// to improve performance; no changes will be made to it.</param>
//    //public static void SetTransformFromMatrix(Transform transform, ref Matrix4x4 matrix)
//    //{
//    //    transform.localPosition = ExtractTranslationFromMatrix(ref matrix);
//    //    transform.localRotation = ExtractRotationFromMatrix(ref matrix);
//    //    transform.localScale = ExtractScaleFromMatrix(ref matrix);
//    //}

//    // EXTRAS!

//    /// <summary>
//    /// Identity XQuaternion.
//    /// </summary>
//    /// <remarks>
//    /// <para>It is faster to access this variation than <c>XQuaternion.identity</c>.</para>
//    /// </remarks>
//    public static readonly XQuaternion IdentityXQuaternion = XQuaternion.identity;

//    /// <summary>
//    /// Identity matrix.
//    /// </summary>
//    /// <remarks>
//    /// <para>It is faster to access this variation than <c>Matrix4x4.identity</c>.</para>
//    /// </remarks>
//    public static readonly Matrix4x4 IdentityMatrix = Matrix4x4.identity;

//    ///// <summary>
//    ///// Get translation matrix.
//    ///// </summary>
//    ///// <param name="offset">Translation offset.</param>
//    ///// <returns>
//    ///// The translation transform matrix.
//    ///// </returns>
//    //public static Matrix4x4 TranslationMatrix(XVector3 offset)
//    //{
//    //    Matrix4x4 matrix = IdentityMatrix;
//    //    matrix.m03 = offset.x;
//    //    matrix.m13 = offset.y;
//    //    matrix.m23 = offset.z;
//    //    return matrix;
//    //}
//}